Skip to content

Add automatic resource management design#12

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-automatic-resource-management
Draft

Add automatic resource management design#12
Copilot wants to merge 2 commits into
mainfrom
copilot/add-automatic-resource-management

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 27, 2025

Design document for deterministic resource cleanup in Zena, addressing opt-in vs automatic semantics, the Disposable protocol, and visibility concerns for disposal methods.

Key Decisions

  • Opt-in with using keyword — WASM-GC lacks destructors/finalizers; automatic RAII-style cleanup isn't feasible without an ownership system
  • _dispose() protected method — Uses existing _ prefix convention for visibility, hides from autocomplete, no symbol infrastructure needed
  • DisposableGroup — LIFO disposal for multiple resources, clearer name than "Stack"
  • Lint warnings — Mitigates hazard of forgetting using on disposable types

Proposed Syntax

{
  using file = openFile('data.txt');
  let data = file.read();
} // file._dispose() called automatically

// Multiple resources with group
{
  using group = new DisposableGroup();
  let a = group.use(openFile('a.txt'));
  let b = group.use(openFile('b.txt'));
} // Both disposed in reverse order

Files

  • docs/design/resource-management.md — Full design with language survey, Zena constraints analysis, implementation plan
  • .github/copilot-instructions.md — Added reference to new design doc
Original prompt

This section details on the original issue you should resolve

<issue_title>Add automatic resource management design</issue_title>
<issue_description>We want a system kind of like JavaScript's automatic resource management, where objects can implement a Disposable interface and have their dispose() method called automatically when they go out of scope.

JavaScript resource management is opt-in: you have to declare a non-mutable variable with using. Should Zena's system be opt-in or could it be automatic because it's statically compiled and has a sound type system? Is automatic even desired, or is opt-in easier to understand. If it's opt-in how can we reduce the hazard of accidentally not opting in and leaving resources un-disposed.

Do we need something like JavaScript's DisposableStack (I like the name DisposableGroup better)?

Zena currently doesn't have protected class members, symbol-keyed fields, or any kind of field namespacing. What would we want out of Zena on that front to build a Disposable protocol, where the relevant methods shouldn't be very public (they should at least be hidden by default in IDEs and such).

This issue will be satisfied by a design document in the docs/design folder. It should discuss other the approaches other languages take, and why we choose a particular one for Zena given Zena's goals and architecture.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: justinfagnani <522948+justinfagnani@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic resource management design Add automatic resource management design Nov 27, 2025
Copilot AI requested a review from justinfagnani November 27, 2025 21:00
@justinfagnani justinfagnani force-pushed the main branch 2 times, most recently from d8f9f3d to 0a9c643 Compare January 3, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs] Add automatic resource management design

2 participants